package com.fancy.projecty.A_流程相关;

import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.runtime.ProcessInstance;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;


/**
 * 启动流程
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class B_启动流程定义_通过流程定义的key {
	@Autowired
	/*管理流程定义,部署相关的Service*/
	private RepositoryService repositoryService;
	@Autowired
	/*执行管理、包括启动、推进、删除流程实例等操作*/
	private RuntimeService runtimeService;
	@Autowired
	/*任务管理,可以做任务的查询的*/
	private TaskService taskService;


	/**
	 * 启动流程实例,在启动流程实例之前必须是先部署好的
	 * 背后影响的表：
	 * act_hi_actinst     已完成的活动信息
	 * act_hi_identitylink   参与者信息
	 * act_hi_procinst   流程实例
	 * act_hi_taskinst   任务实例
	 * act_ru_execution   执行表
	 * act_ru_identitylink   参与者信息
	 * act_ru_task  任务
	 */
	@Test
	public void c_2启动流程实例() {

		//通过流程定义的key来做到流程实例的启动
		ProcessInstance holiday = this.runtimeService.startProcessInstanceByKey("holiday");

		//下面是获取启动了流程实例的信息

		//流程部署ID
		String deploymentId = holiday.getDeploymentId();
		System.out.println("deploymentId = " + deploymentId); //null
		//流程定义id
		String processDefinitionId = holiday.getProcessDefinitionId();
		System.out.println("processDefinitionId = " + processDefinitionId);  //processDefinitionId = holiday:2:2504
		//流程实例id ,是自己的唯一id号
		String id = holiday.getId();
		System.out.println("id = " + id);  //id = 5001
		//活动id 当前正在执行的某一节点是什么
		String activityId = holiday.getActivityId();
		System.out.println("activityId = " + activityId); // null

	}

	/**
	 * 根据tenantid和processDefinitionKey来启动流程
	 */
	@Test
	public void c_根据tenantid和processDefinitionKey来启动流程() {
		this.runtimeService.startProcessInstanceByKeyAndTenantId("holiday", "fsdfsfsgsdgsdfsdf");
	}




}
